import yargs from 'yargs';
import { clearNpxCacheModules, listNpxCacheModules, outputNpxCacheDir, removeNpxCacheModules } from './execute';

export async function npmCacheCli() {
  yargs(process.argv.slice(2))
    .scriptName('npx-cache')
    .help()
    .version()
    .command('dir', 'show npx cache dir', () => void 0, outputNpxCacheDir)
    .command('list', 'list npx cache modules', () => void 0, () => listNpxCacheModules())
    .command('clear', 'clear all npx cache modules', () => void 0, clearNpxCacheModules)
    .command('search <keywords...>', 'search npx cache module', (argv) => {
      return argv.positional('keywords', {
        describe: 'search keywords',
        default : [],
      });
    }, ({ keywords }) => listNpxCacheModules(keywords as string[]))
    .command('remove <names...>', 'remove npx cache module by names', (argv) => {
      return argv.positional('names', {
        describe: 'remove module names',
        default : [],
      });
    }, ({ names }) => removeNpxCacheModules(names as string[]))
    .parseSync()
  ;
}
